﻿<UserControl x:Class="Ewav.XYChartControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:GadgetSelector="clr-namespace:Ewav.ContextMenu;assembly=Ewav.ContextMenu.Menu"
	xmlns:Common="clr-namespace:CommonLibrary;assembly=CommonLibrary"
	mc:Ignorable="d"
	d:DesignHeight="500" d:DesignWidth="900"
	xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
	xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"         
	xmlns:my="clr-namespace:ComponentArt.Silverlight.DataVisualization.Charting;assembly=ComponentArt.Silverlight.DataVisualization.Charting"       
	xmlns:my1="clr-namespace:ComponentArt.Silverlight.DataVisualization.Utils;assembly=ComponentArt.Silverlight.DataVisualization.Common"
	xmlns:dvCharting="clr-namespace:ComponentArt.Silverlight.DataVisualization.Charting;assembly=ComponentArt.Silverlight.DataVisualization.Charting"
	xmlns:dvCommon="clr-namespace:ComponentArt.Silverlight.DataVisualization.Common;assembly=ComponentArt.Silverlight.DataVisualization.Common"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
	DataContext="{Binding Source={StaticResource Locator}, Path=XYChartViewModel}">
    <UserControl.Resources>
        <my1:DetachFromVisualTree x:Key="ComponentArt_DashboardPanel_DetachFromVisualTree"/>
        <Style x:Key="DashboardPanelStyle1" TargetType="dvCommon:DashboardPanel">
            <Setter Property="Margin" Value="2"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="VerticalAlignment" Value="Stretch"/>
            <Setter Property="FontFamily" Value="Lucida Sans Unicode"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="dvCommon:DashboardPanel">
                        <Grid x:Name="LayoutRoot" DataContext="{x:Null}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="ContentLoadStates">
                                    <VisualState x:Name="ContentLoaded">
                                        <Storyboard>
                                            <DoubleAnimation BeginTime="00:00:00" Duration="00:00:00.2" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Content"/>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Cover">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Collapsed"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="ContentNotLoaded">
                                        <Storyboard>
                                            <DoubleAnimation BeginTime="00:00:00" Duration="00:00:00.2" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Content"/>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Cover">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00.2" Value="Visible"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border BorderThickness="0" CornerRadius="4">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{Binding}" HorizontalAlignment="Stretch" Height="23" Margin="8,3" Grid.Row="0" Visibility="{TemplateBinding HeaderVisibility}" VerticalAlignment="Stretch" OpacityMask="Black"/>
                                    <Grid Grid.Row="1">
                                        <Border CornerRadius="0,0,4,4" d:IsHidden="True"/>
                                        <ContentPresenter x:Name="Content" HorizontalAlignment="Stretch" Margin="2,2" Opacity="0" VerticalAlignment="Stretch"></ContentPresenter>
                                        <Grid x:Name="Cover" Background="Transparent" IsHitTestVisible="True" d:IsHidden="True"/>
                                    </Grid>
                                </Grid>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid>
                            <StackPanel Grid.Column="0" HorizontalAlignment="Center" Orientation="Horizontal" VerticalAlignment="Center">
                                <TextBlock Foreground="#000" FontSize="14" FontWeight="Bold" HorizontalAlignment="Center" LineStackingStrategy="BlockLineHeight" LineHeight="20"  Text="{Binding Title}"/>
                                <TextBlock Foreground="{Binding AccentBrush}" FontSize="9" LineStackingStrategy="BlockLineHeight" LineHeight="20" Margin="0,0,3,0" Text="{Binding SubTitle}"/>
                            </StackPanel>
                            <ContentPresenter ContentTemplate="{x:Null}" Content="{Binding HeaderContent, Converter={StaticResource ComponentArt_DashboardPanel_DetachFromVisualTree}}" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <my:DataPointPopup x:Key="CustomDataPointPopup">
            <my:DataPointPopup.ValueTemplate>
                <DataTemplate>
                    <Border CornerRadius="4" Padding="10">
                        <Grid Width="80">
                            <Border Background="{Binding DataPoint.Brush}" Opacity="0.6" CornerRadius="3" Margin="-5 -2 -5 -2"/>
                            <!--<TextBlock Text="{Binding DataPoint.X}" Foreground="Black" HorizontalAlignment="Left" FontWeight="Bold" Grid.Row="0" Grid.Column="0"/>-->
                            <TextBlock Text="{Binding DataPoint.Y}"  HorizontalAlignment="Left" FontWeight="Bold" Grid.Row="0" Grid.Column="1"/>
                            <dvCommon:CalcContainer>
                                <dvCommon:CalcContainer.Computing>
                                    <sys:String>
                                        var sum = 0;
                                var i = 0;
                                while (DataPoint.Chart.DataSeries['S0'].DataPoints.Count > i)
                                {
                                  sum = sum + DataPoint.Chart.DataSeries['S0'].DataPoints[i].Y;
                                  i = i + 1;
                                };
                                var data = '??';
                                if (sum > 0)
                                {
                                  data = DataPoint.Y / sum 
                                };
                                Data = data;
                                    </sys:String>
                                </dvCommon:CalcContainer.Computing>
                                <my:FormattedTextBlock  Format="0%" HorizontalAlignment="Right" FontWeight="Bold" Grid.Row="0" Grid.Column="2" >
                                </my:FormattedTextBlock>
                            </dvCommon:CalcContainer>
                        </Grid>
                    </Border>
                </DataTemplate>
            </my:DataPointPopup.ValueTemplate>
        </my:DataPointPopup>      
                    <DataTemplate x:Key="cdpa">
            <Border Background="#70ffcece" CornerRadius="4" Padding="6,3,6,3" BorderBrush="#FFc4c4c4" BorderThickness="0.5">
                <StackPanel Orientation="Vertical">

                    <TextBlock Text="{Binding DataPoint.X}" Foreground="#FF333333" FontWeight="Bold" FontSize="8.5" HorizontalAlignment="Left"/>
                    <!--<TextBlock Text=" : " Foreground="Black" FontWeight="Bold" FontSize="8"/>-->
                    <dvCommon:CalcContainer>
                        <dvCommon:CalcContainer.Computing>
                            <sys:String>
                                var sum = 0;
                                            var i = 0;
                                            while (DataPoint.Chart.DataSeries['S0'].DataPoints.Count > i)
                                            {
                                                sum = sum + DataPoint.Chart.DataSeries['S0'].DataPoints[i].Y;
                                            i = i + 1
                                            };
                                            var data = '??';
                                            if (sum > 0)
                                            {
                                                data = DataPoint.Y / sum 
                                            };
                                            Data = data;
                            </sys:String>
                        </dvCommon:CalcContainer.Computing>

                        <my:FormattedTextBlock Format="0%" FontSize="9.5" HorizontalAlignment="Left" x:Name="percentText">
                        </my:FormattedTextBlock>

                    </dvCommon:CalcContainer>

                </StackPanel>
            </Border>
        </DataTemplate>
                
            
        
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" MouseRightButtonDown="LayoutRoot_MouseRightButtonDown" 
		  MouseLeftButtonDown="LayoutRoot_MouseLeftButtonDown">

        <Grid x:Name="GadgetWindow" Background="White" MinWidth="400" Margin="0,0,-450,0" >
        	<Grid.RowDefinitions>
        		<RowDefinition Height="50"/>
        		<RowDefinition/>
        	</Grid.RowDefinitions>
        	<Grid.ColumnDefinitions>
        		<ColumnDefinition Width="Auto"/>
        		<ColumnDefinition/>
        	</Grid.ColumnDefinitions>
            
            <Rectangle x:Name="GWindow" Style="{StaticResource GWindow}" Stroke="{StaticResource WindowBrush}" StrokeThickness="4" Grid.RowSpan="2" Grid.ColumnSpan="2" />
        	<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="13,11,0,0" d:LayoutOverrides="VerticalAlignment, GridBox">
        		<TextBlock x:Name="tbChartName" TextWrapping="Wrap"  VerticalAlignment="Top" Margin="0,0,26,0" Height="Auto" Foreground="#FF2B4360" FontSize="21.333" HorizontalAlignment="Left" Text="Chartname"/>
                <Rectangle x:Name="GHeader" VerticalAlignment="Top" Height="4" Margin="0,2,0,0" StrokeThickness="0" Fill="#FF00B050" />
                <!--<TextBlock x:Name="tbDescription" TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,0,26,0" Height="Auto" HorizontalAlignment="Left" Foreground="#FF2B4360" Width="200"/>-->
            </StackPanel>
        	<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Top" Margin="180,9,10,0" Grid.Column="1">
        		<Button x:Name="FilterButton" Content="" Template="{StaticResource FilterButton}" Cursor="Hand" Click="FilterButton_Click" Width="24" Height="24" Visibility="Visible" IsEnabled="False" >
        			<Button.Effect>
        				<DropShadowEffect Color="#FFB0B0B0" ShadowDepth="1"/>
        			</Button.Effect>
        		</Button>
        		<Button x:Name="HeaderButton" Content="" Template="{StaticResource HeaderButton}" Cursor="Hand" Click="HeaderButton_Click"  Width="24" Height="24" IsEnabled="False" >
        			<Button.Effect>
        				<DropShadowEffect Color="#FFB0B0B0" ShadowDepth="1"/>
        			</Button.Effect>
        		</Button>
        		<Button x:Name="ResizeButton" Content="" Template="{StaticResource resizebtn}" Cursor="Hand" Click="ResizeButton_Click" Width="24" Height="24" >
        			<Button.Effect>
        				<DropShadowEffect Color="#FFB0B0B0" ShadowDepth="1"/>
        			</Button.Effect>
        		</Button>
        		<Button x:Name="CloseButton" Content="" Template="{StaticResource CloseButton}" Cursor="Hand" Click="CloseButton_Click" Width="24" Height="24" >
        			<Button.Effect>
        				<DropShadowEffect Color="#FFB0B0B0" ShadowDepth="1"/>
        			</Button.Effect>
        		</Button>
        	</StackPanel>
            
        	<Grid x:Name="GadgetContentGrid" Grid.Row="1" MinHeight="30" Margin="0,5,0,0" Grid.ColumnSpan="2"> 
        		<toolkit:Expander Margin="0,-45,131,0" VerticalAlignment="Top" 
        			ExpandDirection="Down" IsExpanded="True" Style="{StaticResource ExpanderStyle2}" Canvas.ZIndex="999" HorizontalAlignment="Right" Width="188" x:Name="gadgetExpander">
        			<toolkit:Expander.Header>
        				<TextBlock Text="Edit Properties" FontFamily="Segoe UI" Cursor="Hand" FontSize="13.333" FontWeight="Normal" Foreground="White"/>
        			</toolkit:Expander.Header>
        			<Grid Background="#FF5C53AC" Margin="0,-2,1,10" Width="178" HorizontalAlignment="Right">
        				<StackPanel Margin="4,6,4,8" VerticalAlignment="Top" HorizontalAlignment="Center" Width="168">
                          
        					<StackPanel x:Name="pnlSingleConfig" Visibility="Collapsed">
        						<TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Primary Field:" Margin="0,5,0,0" Foreground="White"  />
        						<ComboBox x:Name="cbxSingleField" HorizontalAlignment="Left" Width="166" SelectedIndex="0" SelectionChanged="cbxField_SelectionChanged" />
        						<TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Weight Field:" Margin="0,5,0,0" Foreground="White"  />
        						<ComboBox x:Name="cbxWeightField" HorizontalAlignment="Left" Width="166" SelectedIndex="0"  SelectionChanged="cbxField_SelectionChanged" />
        						<TextBlock x:Name="tblockStrataField"  HorizontalAlignment="Left" TextAlignment="Center" Text="Stratify By:" Margin="0,5,0,0" Foreground="White"  />
        						<ComboBox x:Name="cbxStrataField" HorizontalAlignment="Left" Width="166" SelectedIndex="0"  SelectionChanged="cbxField_SelectionChanged" />
        						<TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Chart size:" Margin="0,5,0,0" Foreground="White" Visibility="Collapsed"  />
        						<ComboBox x:Name="cbxChartSize" HorizontalAlignment="Left" Width="166" Visibility="Collapsed" >
        							<!--<ComboBoxItem Content="Small"   IsSelected="True" />
                                    <ComboBoxItem Content="Medium" />
                                    <ComboBoxItem Content="Large"/>-->
        						</ComboBox>
        						<!--<CheckBox x:Name="checkboxAllValues" Margin="0,5,0,0" Content="Display all list values"  HorizontalAlignment="Left" IsEnabled="false"/>-->
        					</StackPanel>
        					<StackPanel x:Name="pnlStackedColumnConfig" Visibility="Collapsed">
        						<TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="X-Axis Field:" Margin="0,5,0,0" Foreground="White"  />
        						<ComboBox x:Name="cbxColumnXAxisField" HorizontalAlignment="Left" Width="166" SelectedIndex="0"  SelectionChanged="cbxField_SelectionChanged" />
        						<TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Outcome Field:" Margin="0,5,0,0" Foreground="White"  />
        						<ComboBox x:Name="cbxColumnYAxisField" HorizontalAlignment="Left" Width="166" SelectedIndex="0"  SelectionChanged="cbxField_SelectionChanged" />
        						<TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Aggregate Function:" Margin="0,5,0,0" Foreground="White"  />
        						<ComboBox x:Name="cbxColumnAggregateFunc" HorizontalAlignment="Left" Width="166" SelectedIndex="0">
        							<ComboBoxItem Content="Count"/>
        							<ComboBoxItem Content="Count %"/>
        						</ComboBox>
        					</StackPanel>
        					<!--<StackPanel Name="pnlPieChart" Visibility="Visible">
                                <my:PieChart x:Name="PieChart1" XPath="IndependentValue"  ChartKind="Pie2D"  LegendVisible="True" LegendDock="Bottom"
         Width="500" Height="500">
                                    <my:PieSeries Id="pieSeries1" YPath="DependentValue" ShowPointAnnotations="True" x:Name="pieS">
                                        <my:PieSeries.DataPointAnnotations>
                                            <my:DataPointAnnotation>
                                                <my:DataPointAnnotation.Template>
                                                    <DataTemplate>

                                                        <dvCommon:CalcContainer>
                                                            <dvCommon:CalcContainer.Computing>
                                                                <sys:String>
                                                                    var sum = 0;
                                            var i = 0;
                                            while (DataPoint.Chart.DataSeries['pieSeries1'].DataPoints.Count > i)
                                            {
                                                sum = sum + DataPoint.Chart.DataSeries['pieSeries1'].DataPoints[i].DependentValue;
                                            i = i + 1
                                            };
                                            var data = '??';
                                            if (sum > 0)
                                            {
                                                data = DataPoint.DependentValue / sum 
                                            };
                                            Data = data;
                                                                </sys:String>
                                                            </dvCommon:CalcContainer.Computing>
                                                            <my:FormattedTextBlock FontSize="13" Format="0%" FontFamily="Calibri" >
                                                            </my:FormattedTextBlock>
                                                        </dvCommon:CalcContainer>
                                                    </DataTemplate>
                                                </my:DataPointAnnotation.Template>
                                            </my:DataPointAnnotation>
                                        </my:PieSeries.DataPointAnnotations>
                                    </my:PieSeries>
                                </my:PieChart>
                            </StackPanel>-->
        					<Button x:Name="btnRun"  Click="btnRun_Click" Margin="0,11,0,1" Content="Run Gadget" Style="{StaticResource btnSec}" HorizontalAlignment="Center" Width="105" Height="28" >
        						<!--Click="btnRun_Click">-->
        					</Button>
        				</StackPanel>
        			</Grid>
        		</toolkit:Expander>
        		<StackPanel x:Name="spContent" Orientation="Vertical" Margin="10">
        			<StackPanel x:Name="pnlStatus" Height="58" MaxHeight="40" Width="Auto" Background="#FFf8d7e2" Visibility="Collapsed" VerticalAlignment="Top" Margin="0,5">
        				<StackPanel x:Name="pnlStatusTop" Height="2" Width="Auto" Background="#FFe4658e"/>
        				<Image x:Name="ErrorIcon" Source="../../Images/error.png" Width="18" Height="18" HorizontalAlignment="Left" Margin="5,1,5,0" VerticalAlignment="Center"/>
        				<TextBlock x:Name="txtStatus" Text="Error: Exception occurred." TextWrapping="Wrap" Margin="30,-15,5,5" HorizontalAlignment="Left" FontWeight="Bold" VerticalAlignment="Center"/>
        			</StackPanel>
        			<StackPanel x:Name="panelMain" HorizontalAlignment="Left" VerticalAlignment="Top">
        				<TextBlock x:Name="tbGadgetDescription" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="3,3,0,6" Visibility="Visible" MaxWidth="650" Padding="0,0,10,0"  />
        				<Grid x:Name="grdChart" HorizontalAlignment="Left"  VerticalAlignment="Top" Margin="0,10,0,0">
        					<StackPanel x:Name="pnlChartContainer"  Visibility="Visible" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        				</Grid>
        				<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        					<TextBlock x:Name="lblNumberOfRecords" Text="N = " HorizontalAlignment="Left" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment" Margin="0,0,6,15" Height="18" Visibility="Collapsed"/>
        					<TextBlock x:Name="tbNumberOfRecords" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0" Visibility="Visible"  />
        				</StackPanel>
        			</StackPanel>
        		</StackPanel>
        		<Grid x:Name="waitCursor" Background="#36C4C4C4" Height="Auto" Visibility="Collapsed">
        			<toolkit:BusyIndicator x:Name="BusyIndicator" IsBusy="True" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="100" />
        		</Grid>
        	</Grid>

        </Grid>
    </Grid>
</UserControl>
